home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Libraries / WASTE 1.1a4 / Demo Source / WEDemoMenus.p < prev    next >
Encoding:
Text File  |  1994-11-13  |  17.0 KB  |  744 lines  |  [TEXT/PJMM]

  1. unit DemoMenus;
  2.  
  3. { WASTE DEMO PROJECT: }
  4. { Menu Handling }
  5.  
  6. { Copyright © 1993-1994 Merzwaren }
  7. { All Rights Reserved }
  8.  
  9. interface
  10.     uses
  11.         DemoIntf;
  12.  
  13.     function InitializeMenus: OSErr;
  14.     procedure PrepareMenus;
  15.     procedure DoMenuChoice (menuChoice: LongInt);
  16.     function DoClose (closing: ClosingOption;
  17.                                     saving: SavingOption;
  18.                                     window: WindowPtr): OSErr;
  19.     function DoQuit (saving: SavingOption): OSErr;
  20.  
  21. implementation
  22.     uses
  23.         Aliases, DemoFiles, DemoWindows, DialogUtils, Script;
  24.  
  25.     procedure SetDefaultDirectory (vRefNum: Integer;
  26.                                     dirID: LongInt);
  27.  
  28. { Q&D inline to set the default volume and directory used by Standard File }
  29. { I'm afraid this may not work under System >= 7.5 or with certain third-party extensions }
  30.  
  31.     inline
  32.         $21DF, $0398,        { move.l (sp)+, CurDirStore }
  33.         $301F,                     { move.w (sp)+, d0 }
  34.         $4440,                     { neg.w d0 }
  35.         $31C0, $0214;        { move.w d0, SFSaveDisk }
  36.  
  37.     function SFDialogFilter (dialog: DialogPtr;
  38.                                     var event: EventRecord;
  39.                                     var item: Integer;
  40.                                     yourData: Ptr): Boolean;
  41.     begin
  42.         SFDialogFilter := DialogFilter(dialog, event, item);
  43.     end;  { SFDialogFilter }
  44.  
  45.     function FindMenuItem (menu: MenuHandle;
  46.                                     stringToFind: Str255): Integer;
  47.         var
  48.             item: Integer;
  49.             itemString: Str255;
  50.     begin
  51.         for item := CountMItems(menu) downto 1 do
  52.             begin
  53.                 GetItem(menu, item, itemString);
  54.                 if EqualString(itemString, stringToFind, false, false) then
  55.                     Leave;
  56.             end;
  57.         FindMenuItem := item;
  58.     end;  { FindMenuItem }
  59.  
  60.     procedure PrepareMenus;
  61.         var
  62.             window: WindowPtr;
  63.             menu: MenuHandle;
  64.             item: Integer;
  65.             itemString: Str255;
  66.             selStart, selEnd: LongInt;
  67.             actionKind: WEActionKind;
  68.             mode: Integer;
  69.             ts: TextStyle;
  70.             temp: Boolean;
  71.             alignment: SignedByte;
  72.     begin
  73.  
  74. { get a pointer to the frontmost window, if any }
  75.         window := FrontWindow;
  76.  
  77. { *** FILE MENU *** }
  78.         menu := GetMHandle(kMenuFile);
  79.  
  80. { first disable all items }
  81.         for item := CountMItems(menu) downto 1 do
  82.             DisableItem(menu, item);
  83.  
  84. { New, Open and Quit are always enabled }
  85.         EnableItem(menu, kItemNew);
  86.         EnableItem(menu, kItemOpen);
  87.         EnableItem(menu, kItemQuit);
  88.  
  89. { enable Close and Save As if there is an active window }
  90.         if (window <> nil) then
  91.             begin
  92.                 EnableItem(menu, kItemClose);
  93.                 EnableItem(menu, kItemSaveAs);
  94.  
  95. { enable Save if the active window is dirty and has an associated file }
  96.                 if (WEGetModCount(DocumentPeek(window)^.hWE) > 0) and (DocumentPeek(window)^.fileAlias <> nil) then
  97.                     EnableItem(menu, kItemSave);
  98.             end;
  99.  
  100. { *** EDIT MENU *** }
  101.         menu := GetMHandle(kMenuEdit);
  102.  
  103. { first disable all items }
  104.         for item := CountMItems(menu) downto 1 do
  105.             DisableItem(menu, item);
  106.  
  107. { by default, the Undo menu item should read "Can't Undo" }
  108.         GetIndString(itemString, kUndoStringsID, 1);
  109.         SetItem(menu, kItemUndo, itemString);
  110.  
  111.         if (window <> nil) then
  112.             begin
  113.  
  114. { enable Paste if there's anything pasteable on the Clipboard }
  115.                 if (WECanPaste) then
  116.                     EnableItem(menu, kItemPaste);
  117.  
  118. { enable Undo if anything can be undone }
  119.                 actionKind := WEGetUndoInfo(temp, DocumentPeek(window)^.hWE);
  120.                 if (actionKind <> weAKNone) then
  121.                     begin
  122.                         EnableItem(menu, kItemUndo);
  123.  
  124. { change the Undo menu item to "Undo"/"Redo" + name of action to undo }
  125.                         GetIndString(itemString, kUndoStringsID, 2 * actionKind + ORD(temp));
  126.                         SetItem(menu, kItemUndo, itemString);
  127.                     end;
  128.  
  129. { enable Select All if there is anything to select }
  130.                 if (WEGetTextLength(DocumentPeek(window)^.hWE) > 0) then
  131.                     EnableItem(menu, kItemSelectAll);
  132.  
  133. { get the current selection range }
  134.                 WEGetSelection(selStart, selEnd, DocumentPeek(window)^.hWE);
  135.                 if (selStart <> selEnd) then
  136.                     begin
  137.  
  138. { enable Cut, Copy and Clear if the selection range is not empty }
  139.                         EnableItem(menu, kItemCut);
  140.                         EnableItem(menu, kItemCopy);
  141.                         EnableItem(menu, kItemClear);
  142.                     end;
  143.  
  144. { determine which style attributes are continuous over the current selection range }
  145. { we'll need this information in order to check the Font/Size/Style menus properly }
  146.                 mode := weDoFont + weDoSize + weDoFace;        { query about these attributes }
  147.                 temp := WEContinuousStyle(mode, ts, DocumentPeek(window)^.hWE);
  148.             end
  149.         else
  150.             mode := 0;        { no window; so check no item }
  151.  
  152. { *** FONT MENU *** }
  153.         menu := GetMHandle(kMenuFont);
  154.  
  155. { first remove all check marks }
  156.         for item := CountMItems(menu) downto 1 do
  157.             CheckItem(menu, item, false);
  158.  
  159. { if there is a continuous font all over the selection range, }
  160. { check the corresponding menu item }
  161.         if (BitAnd(mode, weDoFont) <> 0) then
  162.             begin
  163.                 GetFontName(ts.tsFont, itemString);
  164.                 CheckItem(menu, FindMenuItem(menu, itemString), true);
  165.             end;
  166.  
  167. { *** SIZE MENU *** }
  168.         menu := GetMHandle(kMenuSize);
  169.  
  170. { first remove all check marks }
  171.         for item := CountMItems(menu) downto 1 do
  172.             CheckItem(menu, item, false);
  173.  
  174. { if there is a continuous font size all over the selection range, }
  175. { check the corresponding menu item }
  176.         if (BitAnd(mode, weDoSize) <> 0) then
  177.             begin
  178.                 NumToString(ts.tsSize, itemString);
  179.                 CheckItem(menu, FindMenuItem(menu, itemString), true);
  180.             end;
  181.  
  182. { *** STYLE MENU *** }
  183.         menu := GetMHandle(kMenuStyle);
  184.  
  185. { first remove all check marks }
  186.         for item := CountMItems(menu) downto 1 do
  187.             CheckItem(menu, item, false);
  188.  
  189. { check the Style menu items corresponding to style attributes }
  190. { which are continuous over the current selection range }
  191.         if (BitAnd(mode, weDoFace) <> 0) then
  192.             begin
  193.  
  194.                 if (ts.tsFace = []) then
  195.                     CheckItem(menu, kItemPlainText, true);
  196.  
  197.                 if (bold in ts.tsFace) then
  198.                     CheckItem(menu, kItemBold, true);
  199.  
  200.                 if (italic in ts.tsFace) then
  201.                     CheckItem(menu, kItemItalic, true);
  202.  
  203.                 if (underline in ts.tsFace) then
  204.                     CheckItem(menu, kItemUnderline, true);
  205.  
  206.                 if (outline in ts.tsFace) then
  207.                     CheckItem(menu, kItemOutline, true);
  208.  
  209.                 if (shadow in ts.tsFace) then
  210.                     CheckItem(menu, kItemShadow, true);
  211.  
  212.                 if (condense in ts.tsFace) then
  213.                     CheckItem(menu, kItemCondensed, true);
  214.  
  215.                 if (extend in ts.tsFace) then
  216.                     CheckItem(menu, kItemExtended, true);
  217.  
  218.             end;
  219.  
  220. { *** ALIGNMENT MENU *** }
  221.         menu := GetMHandle(kMenuAlignment);
  222.  
  223. { first remove all check marks }
  224.         for item := CountMItems(menu) downto 1 do
  225.             CheckItem(menu, item, false);
  226.  
  227.         if (window <> nil) then
  228.             begin
  229.  
  230. { get the current alignment style }
  231.                 alignment := WEGetAlignment(DocumentPeek(window)^.hWE);
  232.  
  233. { find the corresponding Alignment menu item }
  234.                 case alignment of
  235.  
  236.                     weFlushLeft: 
  237.                         item := kItemAlignLeft;
  238.  
  239.                     weFlushRight: 
  240.                         item := kItemAlignRight;
  241.  
  242.                     weFlushDefault: 
  243.                         if (GetSysJust = 0) then
  244.                             item := kItemAlignLeft
  245.                         else
  246.                             item := kItemAlignRight;
  247.  
  248.                     weCenter: 
  249.                         item := kItemCenter;
  250.  
  251.                     weJustify: 
  252.                         item := kItemJustify;
  253.  
  254.                 end;  { case }
  255.  
  256. { check the menu item }
  257.                 CheckItem(menu, item, true);
  258.  
  259.             end;
  260.     end;  { PrepareMenus }
  261.  
  262.     procedure DoAbout;
  263.         var
  264.             alertResult: Integer;
  265.     begin
  266.         SetCursor(arrow);
  267.         alertResult := Alert(kAlertAboutBox, @DialogFilter);
  268.     end;  { DoAbout }
  269.  
  270.     procedure DoDeskAcc (menuItem: Integer);
  271.         var
  272.             daName: Str255;
  273.             daNumber: Integer;
  274.     begin
  275.         GetItem(GetMHandle(kMenuApple), menuItem, daName);
  276.         daNumber := OpenDeskAcc(daName);
  277.     end;  { DoDeskAcc }
  278.  
  279.     function DoNew: OSErr;
  280.     begin
  281.  
  282. { create a new window from scratch }
  283.         DoNew := CreateWindow(nil);
  284.     end;  { DoNew }
  285.  
  286.     function DoOpen: OSErr;
  287.         var
  288.             reply: StandardFileReply;
  289.             typeList: SFTypeList;
  290.     begin
  291.         DoOpen := noErr;
  292.  
  293. { set up a list of file types we can open for StandardGetFile }
  294.         typeList[0] := kTypeText;
  295.  
  296. { put up the standard Open dialog box }
  297. { (we use CustomGetFile instead of StandardGetFile because we want to provide }
  298. { our own dialog filter procedure that takes care of updating our windows) }
  299.         CustomGetFile(nil, 1, typeList, reply, 0, Point(-1), nil, @SFDialogFilter, nil, nil, nil);
  300.  
  301. { if the user okayed the dialog, create a new window from the specified file }
  302.         if (reply.sfGood) then
  303.             DoOpen := CreateWindow(@reply.sfFile)
  304.         else
  305.             DoOpen := userCanceledErr;
  306.  
  307.     end;  { DoOpen }
  308.  
  309.     function DoSaveAs (suggestedTarget: FSSpecPtr;
  310.                                     window: WindowPtr): OSErr;
  311.         var
  312.             hPrompt: StringHandle;
  313.             defaultName: Str255;
  314.             reply: StandardFileReply;
  315.             err: OSErr;
  316.     begin
  317.         DoSaveAs := noErr;
  318.  
  319. { get the prompt string for CustomPutFile from a 'STR ' resource and lock it }
  320.         hPrompt := GetString(kPromptStringID);
  321.         HLockHi(Handle(hPrompt));
  322.  
  323. { if a suggested target file is provided, use its name as the default name }
  324.         if (suggestedTarget <> nil) then
  325.             begin
  326.                 defaultName := suggestedTarget^.name;
  327.                 SetDefaultDirectory(suggestedTarget^.vRefNum, suggestedTarget^.parID);
  328.             end
  329.         else
  330.  
  331. { otherwise use the window title as default name for CustomPutFile }
  332.             GetWTitle(window, defaultName);
  333.  
  334. { put up the standard Save dialog box }
  335.         CustomPutFile(hPrompt^^, defaultName, reply, 0, Point(-1), nil, @SFDialogFilter, nil, nil, nil);
  336.  
  337. { unlock the string resource }
  338.         HUnlock(Handle(hPrompt));
  339.  
  340. { if the user okayed the dialog, update the file alias }
  341. { and save the window to the specified file }
  342.         if (reply.sfGood) then
  343.             begin
  344.                 ForgetHandle(DocumentPeek(window)^.fileAlias);
  345.                 err := NewAlias(nil, reply.sfFile, AliasHandle(DocumentPeek(window)^.fileAlias));
  346.                 if (err <> noErr) then
  347.                     begin
  348.                         DoSaveAs := err;
  349.                         Exit(DoSaveAs);
  350.                     end;
  351.                 SetWTitle(window, reply.sfFile.name);
  352.                 DoSaveAs := WriteTextFile(@reply.sfFile, DocumentPeek(window)^.hWE);
  353.             end
  354.         else
  355.             DoSaveAs := userCanceledErr;
  356.  
  357.     end;  { DoSaveAs }
  358.  
  359.     function DoSave (window: WindowPtr): OSErr;
  360.         var
  361.             spec: FSSpec;
  362.             suggestedTarget: FSSpecPtr;
  363.             promptForNewFile, aliasTargetWasChanged: Boolean;
  364.     begin
  365.         DoSave := noErr;
  366.         suggestedTarget := nil;
  367.         promptForNewFile := true;
  368.  
  369. { resolve the alias associated with this window, if any }
  370.         if (DocumentPeek(window)^.fileAlias <> nil) then
  371.             if (ResolveAlias(nil, AliasHandle(DocumentPeek(window)^.fileAlias), spec, aliasTargetWasChanged) = noErr) then
  372.                 if (aliasTargetWasChanged) then
  373.                     suggestedTarget := @spec
  374.                 else
  375.                     promptForNewFile := false;
  376.  
  377. { if no file has been previously associated with this window, }
  378. { or if the alias resolution has failed, or if the alias target was changed, }
  379. { prompt the user for a new destination }
  380.         if (promptForNewFile) then
  381.             DoSave := DoSaveAs(suggestedTarget, window)
  382.         else
  383.             DoSave := WriteTextFile(@spec, DocumentPeek(window)^.hWE);
  384.  
  385.     end;  { DoSave }
  386.  
  387.     function DoClose (closing: ClosingOption;
  388.                                     saving: SavingOption;
  389.                                     window: WindowPtr): OSErr;
  390.         const
  391.             kButtonSave = 1;
  392.             kButtonCancel = 2;
  393.             kButtonDontSave = 3;
  394.         var
  395.             s: Str255;
  396.             alertResult: Integer;
  397.             err: OSErr;
  398.     begin
  399.         DoClose := noErr;
  400.  
  401. { is this window dirty? }
  402.         if (WEGetModCount(DocumentPeek(window)^.hWE) > 0) then
  403.             begin
  404.  
  405. { do we have to ask the user whether to save changes? }
  406.                 if (saving = savingAsk) then
  407.                     begin
  408.  
  409. { prepare the parametric strings to be used in the Save Changes alert box }
  410.                         GetWTitle(window, s);
  411.                         ParamText(s, StringPtr(nil)^, StringPtr(nil)^, StringPtr(nil)^);
  412.                         GetIndString(s, kClosingQuittingStringsID, 1 + ORD(closing));
  413.                         ParamText(StringPtr(nil)^, s, StringPtr(nil)^, StringPtr(nil)^);
  414.  
  415. { put up the Save Changes? alert box }
  416.                         SetCursor(arrow);
  417.                         alertResult := Alert(kAlertSaveChanges, @DialogFilter);
  418.  
  419. { exit if the user canceled the alert box }
  420.                         if (alertResult = kButtonCancel) then
  421.                             begin
  422.                                 DoClose := userCanceledErr;
  423.                                 Exit(DoClose);
  424.                             end;
  425.  
  426.                         if (alertResult = kButtonSave) then
  427.                             saving := savingYes
  428.                         else
  429.                             saving := savingNo;
  430.                     end;  { if saving = savingAsk }
  431.  
  432.                 if (saving = savingYes) then
  433.                     begin
  434.                         err := DoSave(window);
  435.                         if (err <> noErr) then
  436.                             begin
  437.                                 DoClose := err;
  438.                                 Exit(DoClose);
  439.                             end;
  440.                     end;
  441.             end;  { if window is dirty }
  442.  
  443. { destroy the window }
  444.         DestroyWindow(window);
  445.  
  446.     end;  { DoClose }
  447.  
  448.     function DoQuit (saving: SavingOption): OSErr;
  449.         var
  450.             window: WindowPtr;
  451.             err: OSErr;
  452.     begin
  453.         DoQuit := noErr;
  454.  
  455. { close all open windows }
  456.         repeat
  457.             window := FrontWindow;
  458.             if (window <> nil) then
  459.                 begin
  460.                     err := DoClose(closingApplication, saving, window);
  461.                     if (err <> noErr) then
  462.                         begin
  463.                             DoQuit := err;
  464.                             Exit(DoQuit);
  465.                         end;
  466.                 end;
  467.         until (window = nil);
  468.  
  469. { set a flag so we drop out of the event loop }
  470.         gExiting := true;
  471.  
  472.     end;  { DoQuit }
  473.  
  474.     procedure DoAppleChoice (menuItem: Integer);
  475.     begin
  476.         if (menuItem = kItemAbout) then
  477.             DoAbout
  478.         else
  479.             DoDeskAcc(menuItem);
  480.     end;  { DoAppleChoice }
  481.  
  482.     procedure DoFileChoice (menuItem: Integer);
  483.     begin
  484.         case menuItem of
  485.  
  486.             kItemNew: 
  487.                 if (DoNew <> noErr) then
  488.                     ;
  489.  
  490.             kItemOpen: 
  491.                 if (DoOpen <> noErr) then
  492.                     ;
  493.  
  494.             kItemClose: 
  495.                 if (DoClose(closingWindow, savingAsk, FrontWindow) <> noErr) then
  496.                     ;
  497.  
  498.             kItemSave: 
  499.                 if (DoSave(FrontWindow) <> noErr) then
  500.                     ;
  501.  
  502.             kItemSaveAs: 
  503.                 if (DoSaveAs(nil, FrontWindow) <> noErr) then
  504.                     ;
  505.  
  506.             kItemQuit: 
  507.                 if (DoQuit(savingAsk) <> noErr) then
  508.                     ;
  509.  
  510.             otherwise
  511.                 ;
  512.         end;  { case menuItem }
  513.     end;  { DoFileChoice }
  514.  
  515.     procedure DoEditChoice (menuItem: Integer);
  516.         var
  517.             window: WindowPtr;
  518.             hWE: WEHandle;
  519.     begin
  520.  
  521. { do nothing if no window is active }
  522.         window := FrontWindow;
  523.         if (window = nil) then
  524.             Exit(DoEditChoice);
  525.         hWE := DocumentPeek(window)^.hWE;
  526.  
  527.         case menuItem of
  528.  
  529.             kItemUndo: 
  530.                 if (WEUndo(hWE) <> noErr) then
  531.                     ;
  532.  
  533.             kItemCut: 
  534.                 if (WECut(hWE) <> noErr) then
  535.                     ;
  536.  
  537.             kItemCopy: 
  538.                 if (WECopy(hWE) <> noErr) then
  539.                     ;
  540.  
  541.             kItemPaste: 
  542.                 if (WEPaste(hWE) <> noErr) then
  543.                     ;
  544.  
  545.             kItemClear: 
  546.                 if (WEDelete(hWE) <> noErr) then
  547.                     ;
  548.  
  549.             kItemSelectAll: 
  550.                 WESetSelection(0, maxLongInt, hWE);
  551.  
  552.             otherwise
  553.                 ;
  554.         end;  { case }
  555.     end;  { DoEditChoice }
  556.  
  557.     procedure DoFontChoice (menuItem: Integer);
  558.         var
  559.             window: WindowPtr;
  560.             fontName: Str255;
  561.             ts: TextStyle;
  562.             err: OSErr;
  563.     begin
  564.         window := FrontWindow;
  565.         if (window <> nil) then
  566.             begin
  567.                 GetItem(GetMHandle(kMenuFont), menuItem, fontName);
  568.                 GetFNum(fontName, ts.tsFont);
  569.                 err := WESetStyle(weDoFont, ts, DocumentPeek(window)^.hWE);
  570.             end;
  571.     end;  { DoFontChoice }
  572.  
  573.     procedure DoSizeChoice (menuItem: Integer);
  574.         var
  575.             window: WindowPtr;
  576.             sizeString: Str255;
  577.             longSize: LongInt;
  578.             mode: Integer;
  579.             ts: TextStyle;
  580.             err: OSErr;
  581.     begin
  582.         window := FrontWindow;
  583.         if (window <> nil) then
  584.             begin
  585.  
  586.                 if (menuItem <= kItemLastSize) then
  587.                     begin
  588.                         GetItem(GetMHandle(kMenuSize), menuItem, sizeString);
  589.                         StringToNum(sizeString, longSize);
  590.                         mode := weDoSize;
  591.                         ts.tsSize := longSize;
  592.                     end
  593.                 else if (menuItem = kItemSmaller) then
  594.                     begin
  595.                         mode := weDoAddSize;
  596.                         ts.tsSize := -1;
  597.                     end
  598.                 else if (menuItem = kItemLarger) then
  599.                     begin
  600.                         mode := weDoAddSize;
  601.                         ts.tsSize := +1;
  602.                     end;
  603.  
  604.                 err := WESetStyle(mode, ts, DocumentPeek(window)^.hWE);
  605.  
  606.             end;
  607.     end;  { DoSizeChoice }
  608.  
  609.     procedure DoStyleChoice (menuItem: Integer);
  610.         var
  611.             window: WindowPtr;
  612.             ts: TextStyle;
  613.             err: OSErr;
  614.     begin
  615.         window := FrontWindow;
  616.         if (window <> nil) then
  617.             begin
  618.  
  619.                 case menuItem of
  620.  
  621.                     kItemPlainText: 
  622.                         ts.tsFace := [];
  623.  
  624.                     kItemBold: 
  625.                         ts.tsFace := [bold];
  626.  
  627.                     kItemItalic: 
  628.                         ts.tsFace := [italic];
  629.  
  630.                     kItemUnderline: 
  631.                         ts.tsFace := [underline];
  632.  
  633.                     kItemOutline: 
  634.                         ts.tsFace := [outline];
  635.  
  636.                     kItemShadow: 
  637.                         ts.tsFace := [shadow];
  638.  
  639.                     kItemCondensed: 
  640.                         ts.tsFace := [condense];
  641.  
  642.                     kItemExtended: 
  643.                         ts.tsFace := [extend];
  644.  
  645.                     otherwise
  646.                         Exit(DoStyleChoice);
  647.                 end;  { case menuItem }
  648.  
  649.                 err := WESetStyle(weDoFace + weDoToggleFace, ts, DocumentPeek(window)^.hWE);
  650.  
  651.             end;
  652.     end;  { DoStyleChoice }
  653.  
  654.     procedure DoAlignChoice (menuItem: Integer);
  655.         var
  656.             window: WindowPtr;
  657.             alignment: SignedByte;
  658.     begin
  659.         window := FrontWindow;
  660.         if (window <> nil) then
  661.             begin
  662.  
  663.                 case menuItem of
  664.  
  665.                     kItemAlignLeft: 
  666.                         alignment := weFlushLeft;
  667.  
  668.                     kItemCenter: 
  669.                         alignment := weCenter;
  670.  
  671.                     kItemAlignRight: 
  672.                         alignment := weFlushRight;
  673.  
  674.                     kItemJustify: 
  675.                         alignment := weJustify;
  676.  
  677.                     otherwise
  678.                         Exit(DoAlignChoice);
  679.                 end;  { case }
  680.  
  681. { set the alignment mode (this automatically redraws the text) }
  682.                 WESetAlignment(alignment, DocumentPeek(window)^.hWE);
  683.  
  684.             end;
  685.     end;  { DoAlignChoice }
  686.  
  687.     procedure DoMenuChoice (menuChoice: LongInt);
  688.         var
  689.             menuID, menuItem: Integer;
  690.     begin
  691.  
  692. { extract menu ID and menu item from menuChoice }
  693.         menuID := HiWord(menuChoice);
  694.         menuItem := LoWord(menuChoice);
  695.  
  696. { dispatch on menuID }
  697.         case menuID of
  698.  
  699.             kMenuApple: 
  700.                 DoAppleChoice(menuItem);
  701.  
  702.             kMenuFile: 
  703.                 DoFileChoice(menuItem);
  704.  
  705.             kMenuEdit: 
  706.                 DoEditChoice(menuItem);
  707.  
  708.             kMenuFont: 
  709.                 DoFontChoice(menuItem);
  710.  
  711.             kMenuSize: 
  712.                 DoSizeChoice(menuItem);
  713.  
  714.             kMenuStyle: 
  715.                 DoStyleChoice(menuItem);
  716.  
  717.             kMenuAlignment: 
  718.                 DoAlignChoice(menuItem);
  719.  
  720.             otherwise
  721.                 ;
  722.         end;  { case menuID }
  723.  
  724.         HiliteMenu(0);
  725.  
  726.     end;  { DoMenuChoice }
  727.  
  728.     function InitializeMenus: OSErr;
  729.     begin
  730.         InitializeMenus := noErr;
  731.  
  732. { build up the whole menu bar from the 'MBAR' resource }
  733.         SetMenuBar(GetNewMBar(kMenuBarID));
  734.  
  735. { add names to the Apple and Font menus }
  736.         AddResMenu(GetMHandle(kMenuApple), kTypeDeskAccessory);
  737.         AddResMenu(GetMHandle(kMenuFont), kTypeFont);
  738.  
  739. { draw the menu bar }
  740.         DrawMenuBar;
  741.  
  742.     end;  { InitializeMenus }
  743.  
  744. end.